/*
 * @Description: 发运自动化规则DS
 * @Version: 1.0
 * @Autor: c-jack.qian
 * @Date: 2020-12-28 20:03:25
 * @LastEditors: c-jack.qian
 * @LastEditTime: 2021-04-25 15:20:41
 */
import { DataSetSelection, FieldType } from 'choerodon-ui/pro/lib/data-set/enum';
import commonConfigStore from '@common/config/commonConfig';
import intl from 'utils/intl';
import { DataSet } from 'choerodon-ui/pro/lib';
const O2_OM = process.env.NODE_ENV === 'development' ? '/o2om-c' : commonConfigStore.O2_OM;


const shippingAutomationRulesDS = () => ({
    autoQuery: true,
    selection: 'multiple',
    primaryKey: 'id',
    transport: {
        read: config => {
            return {
                ...config,
                url: `${O2_OM}/v1/shipping-automation-rules`,
                method: 'get',
            };
        },
        destroy: config => {
            return {
                ...config,
                url: `${O2_OM}/v1/shipping-automation-rules`,
                method: 'delete',
            };
        },
    },
    fields: [
        {
            label: intl.get('dji.otc.om.view.field.groupName').d('组别'),
            name: 'businessGroupCode',
            type: FieldType.string,
            lookupCode: 'DJICM_GROUP',
        },
        {
            label: intl.get('dji.otc.om.view.field.area').d('区域'),
            name: 'areaId',
            type: FieldType.string,
            lookupCode: 'DJIOM_CHOOSE_SMALL_AREA',
        },
        {
            name: 'customerName',
            type: FieldType.string,
            label: intl.get('dji.otc.om.view.field.customerName').d('客户'),
        },
        {
            name: 'tradeTerm',
            type: FieldType.string,
            label: intl.get('dji.otc.om.view.field.tradeTerm').d('贸易术语'),
        },
        {
            name: 'logistics',
            type: FieldType.string,
            label: intl.get('dji.otc.om.view.field.logistics').d('承运方式'),
        },
        {
            name: 'shippingAmount',
            type: FieldType.currency,
            label: intl.get('dji.otc.om.view.field.shippingAmount').d('起运金额'),
        },
        {
            name: 'shippingWeight',
            type: FieldType.number,
            label: intl.get('dji.otc.om.view.field.shippingWeight').d('起运重量'),
        },
        {
            name: 'automationRule',
            type: FieldType.string,
            label: intl.get('dji.otc.om.view.field.automationRule').d('自动化规则'),
        },
        {
            name: 'automationCycle',
            type: FieldType.string,
            label: intl.get('dji.otc.om.view.field.automationCycle').d('自动发运周期'),
        },
    ],
    queryFields: [
        {
            label: intl.get('dji.otc.om.view.field.groupName').d('组别'),
            name: 'businessGroup',
            type: FieldType.string,
            lookupCode: 'DJICM_GROUP',
        },
        {
            label: intl.get('dji.otc.om.view.field.area').d('区域'),
            name: 'areaId',
            type: FieldType.string,
            lookupCode: 'DJIOM_CHOOSE_SMALL_AREA',
        },
        {
            name: 'customerName',
            type: FieldType.string,
            label: intl.get('dji.otc.om.view.field.customerName').d('客户'),
        },
    ],
});

const modalRulesDataSet = () => ({
    autoQuery: true,
    selection: 'multiple',
    primaryKey: 'id',
    paging: false,
    transport: {
        read: config => {
            return {
                ...config,
                url: `${O2_OM}/v1/shipping-automation-rule-details`,
                method: 'get',
            };
        },
        submit: config => {
            const { data } = config
            return {
                ...config,
                data: data[0],
                url: `${O2_OM}/v1/shipping-automation-rule-details`,
                method: 'post',
            };
        },
    },
    fields: [
        {
            name: 'lmsLogistics',
            type: FieldType.string,
            label: intl.get('dji.otc.om.view.field.lmsLogistics').d('承运商'),
            lookupCode: 'DJIOM.AUTOMATION_RULE',
            required: true,
        },
        {
            name: 'shippingAddress',
            type: FieldType.string,
            label: intl.get('dji.otc.om.view.field.shippingAddress').d('收货地址'),
            required: true,
            lookupCode: 'DJIOM.AUTOMATION_RULE',
        },
        {
            name: 'isShowModelNumber',
            type: FieldType.string,
            label: intl.get('dji.otc.om.view.field.isShowModelNumber').d('CI上是否显示Model No'),
            required: true,
            lookupCode: 'DJIOM.AUTOMATION_RULE',
        },
        {
            name: 'isShowCiPoNumber',
            label: intl.get('dji.otc.om.view.field.isShowCiPoNumber').d('CI上是否显示PO No'),
            type: FieldType.string,
            required: true,
            lookupCode: 'DJIOM.AUTOMATION_RULE',
        },
        {
            name: 'emailAddress',
            label: intl.get('dji.otc.om.view.field.emailAddress').d('销售代表'),
            type: FieldType.string,
            required: true,
            lookupCode: 'DJIOM.AUTOMATION_RULE',
        },
        {
            name: 'shippingWarehouse',
            label: intl.get('dji.otc.om.view.field.shippingWarehouse').d('指定发货仓库'),
            type: FieldType.string,
            required: true,
            lookupCode: 'DJPCM_WAREHOUSE',
            textField: 'wareHouseName',
            valueField: 'wareHouseCode',
        },
        {
            name: 'customerEmailAddress',
            type: FieldType.string,
            label: intl.get('dji.otc.om.view.field.customerEmailAddress').d('发货邮件抄送'),
            required: true,
            lookupCode: 'DJIOM.AUTOMATION_RULE',
        },
        {
            name: 'deliverDate',
            type: FieldType.string,
            label: intl.get('dji.otc.om.view.field.deliverDate').d('要求发货日期'),
            required: true,
            lookupCode: 'DJIOM.AUTOMATION_RULE',
        },
        {
            name: 'arrivalDate',
            type: FieldType.string,
            label: intl.get('dji.otc.om.view.field.arrivalDate').d('要求到货日期'),
            required: true,
            lookupCode: 'DJIOM.AUTOMATION_RULE',
        },
        {
            name: 'ciConfirm',
            label: intl.get('dji.otc.om.view.field.ciConfirm').d('CI是否需要销售确认'),
            type: FieldType.number,
            required: true,
            options: isOption
        },
        {
            name: 'overallShipment',
            label: intl.get('dji.otc.om.view.field.overallShipment').d('是否要求整单发货'),
            type: FieldType.string,
            required: true,
            lookupCode: 'DJIOM.AUTOMATION_RULE',
        },
        {
            name: 'dealerOwnAccount',
            label: intl.get('dji.otc.om.view.field.dealerOwnAccount').d('代理商指定承运商账号'),
            type: FieldType.string,
            required: true,
            lookupCode: 'DJIOM.AUTOMATION_RULE',
        },
        {
            name: 'ciAttribute',
            type: FieldType.string,
            label: intl.get('dji.otc.om.view.field.ciAttribute').d('核销CI展示项'),
            required: true,
            lookupCode: 'DJIOM.AUTOMATION_RULE',
        },
    ],
});

const isOption = new DataSet({
    selection: 'single' as DataSetSelection,
    data: [
        { meaning: intl.get('hzero.common.status.yes').d('是'), value: 1 },
        { meaning: intl.get('hzero.common.status.no').d('否'), value: 0 },
    ],
});

export { shippingAutomationRulesDS, modalRulesDataSet };
